﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>后台登陆</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" type="text/css" href="../layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="css/loginCss.css"/>

</head>
<body class="login-body">
<div class="login-box">
    <div class="layui-form-item">
        <h3>
            <span>个人博客后台管理系统</span><br/>
            <span class="version">提示：创建者技术不高，所以攻击者的亲妈在劫难逃 ！</span></h3>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">
            用户名：</label>
        <div class="layui-input-inline">
            <input type="text" id="username" autocomplete="off" class="layui-input" lay-verify="account"
                   placeholder="请输入用户名" maxlength="20"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">
            密码：</label>
        <div class="layui-input-inline">
            <input type="password" id="pass" class="layui-input" lay-verify="password" placeholder="请输入密码"
                   maxlength="20"/>
        </div>
    </div>
    <!--        <div class="layui-form-item" style="display: none;" >&lt;!&ndash;    &ndash;&gt;-->
    <!--            <label class="layui-form-label">-->
    <!--                验证码：</label>-->
    <!--            <div class="layui-input-inline">-->
    <!--                <input type="number" name="verify" autocomplete="off" class="layui-input" lay-verify="verify"-->
    <!--                    placeholder="验证码" maxlength="4" value="1234" /><img id="verify" src="include/checkcode.html"-->
    <!--                        alt="验证码" onclick="this.src='include/checkcode.html?t='+(new Date().getTime());"-->
    <!--                        class="captcha">-->
    <!--            </div>-->
    <!--        </div>-->
    <div class="layui-form-item">
        <button type="reset" class="layui-btn btn-reset layui-btn-danger">
            重置
        </button>
        <button type="button" class="layui-btn" lay-filter="*" id="sub" onclick="sub()">立即登录</button>
    </div>
</div>
<script type="text/javascript" src="/static/layui/layui.js"></script>
<script type="text/javascript" src="/static/js/jquery3.4.0.js"></script>
<script type="text/javascript">
    function sub() {
        var name = $("#username").val();
        var pass = $("#pass").val();
        data = {};
        data.username = name;
        data.password = pass;
        $.ajax({
            type: "POST",
            url: "/auth/login",
            data: JSON.stringify(data),
            contentType: "application/json; charset=utf-8",
            dataType: 'json',//预期服务器返回的数据类型
            success: function (res, headers, response) {
                console.log(res)
                //console.log(response.getAllResponseHeaders);
                if (res.status === "200") {
                    var a = response.getResponseHeader("token");
                    localStorage.setItem("user",JSON.stringify(res.user));
                    localStorage.setItem("token", a);
                    console.log(a);
                    window.location.href = "/main";
                } else if (res === 1040) {
                    layui.use('layer', function () {
                        var layer = layui.layer;
                        layer.msg("输账号和密码都能输歪来!??", {icon: 2, time: 1000}, function () {
                            window.location.href = "/Default";
                        });
                    })

                }
            }
        });
    }
</script>
</body>
</html>
